package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class Util {
	
	public static void ShowError(HttpServletResponse response, String message) throws IOException{
		response.setContentType("text/html; charset=UTF-8");
		PrintWriter out = response.getWriter();
		out.println("<script>");
		out.println("alert('"+message+"');");
		out.println("history.go(-1);");
		out.println("</script>");
		
		out.flush();
		out.close();
	
	}
	
	public static void ShowSuccess(HttpServletResponse response, String message, String location)throws IOException{
		response.setContentType("text/html; charset=UTF-8");
		PrintWriter out = response.getWriter();
		out.println("<script>");
		out.println("alert('"+message+"');");
		out.println("location.href='"+location+"';");
		out.println("</script>");
		out.flush();
		out.close();
	}
	
	public static String toUTF8(String string) throws UnsupportedEncodingException{
		
		string = string!=null ? new String(string.getBytes("ISO-8859-1"), "utf-8"):null;
		return string;
	}

}
